<template>
  <div class="produceFactoryDialog">
    <div class="panelWrap">
      <div class="title flex flexac flexjcsb fs14 cfff fwb pl p-r-20">
        <div>添加</div>
        <i class="el-icon-close" @click="handleCloseDialogUpdate"></i>
      </div>
      <div class="con">
        <div class="con-row">
          <div class="inputLable inputLable1 flex flexac">
            <span class="name"><span class="mustval">*</span>用户设备类型：</span>
            <el-input class="input" placeholder="请输入用户设备类型" value="电梯" readonly></el-input>
          </div>
        </div>
        <div class="con-row">
          <div class="inputLable inputLable1 flex flexac">
            <span class="name"><span class="mustval">*</span>制造商名称：</span>
            <el-input class="input" v-model="addFactory.name" placeholder="请输入制造商名称"></el-input>
          </div>
        </div>
        <div class="con-row">
          <div class="inputLable inputLable1 flex flexac">
            <span class="name">联系人：</span>
            <el-input class="input" v-model="addFactory.contacts" placeholder="请输入联系人"></el-input>
          </div>
        </div>
        <div class="con-row">
          <div class="inputLable inputLable1 flex flexac">
            <span class="name">联系人电话：</span>
            <el-input class="input" v-model="addFactory.phone" placeholder="请输入联系人电话"></el-input>
          </div>
        </div>
        <div class="con-row">
          <div class="inputLable inputLable1 flex flexac">
            <span class="name">地址：</span>
            <el-input class="input" v-model="addFactory.address" placeholder="请输入地址"></el-input>
          </div>
        </div>
        <div class="con-row">
          <div class="inputLable inputLable1 flex flexac flexaifs">
            <span class="name">描述：</span>
            <!-- <el-input class="input" placeholder="请输入描述"></el-input> -->
            <textarea class="input textarea" v-model="addFactory.remark"></textarea>
          </div>
        </div>
      </div>
      <div class="flex flextc footerBtn m-t-35">
        <el-button class="defaultbtn saveBtn" v-if="!isEdit" @click="handleSave">保存</el-button>
        <el-button class="defaultbtn saveBtn" v-else @click="handleUpdate">更新</el-button>
        <el-button class="defaultbtn clsoeBtn" v-if="!isEdit" @click="handleCloseDialog">关闭</el-button>
        <el-button class="defaultbtn clsoeBtn" v-else @click="handleCloseDialogUpdate">关闭</el-button>
      </div>
    </div>
  </div>
</template>

<script>

import { addFactory, updateFactory } from '../../api/table'
import { showNotice, successNotice,checkMobile } from '../../utils/toolclass'

export default {
  props: {
    addFactory: {
      type: Object,
    },
    isEdit: {
      type: Boolean,
    }
  },
  data() {
    return {

    }
  },
  created() {

  },
  components: {

  },
  methods: {
    handleUpdate() {
      updateFactory(this.addFactory).then((res) => {
        if (res.code == "000000") {
          showNotice('success', '提示', '保存成功!')
          this.$emit('handleRefresh');
          this.$emit('handleCloseDialog');
        }
      });
    },
    handleSave() {
      if (this.addFactory.name == '') {
        showNotice('error', '提示', '制造商不能为空!')
      }else if(this.addFactory.phone!==''&& !checkMobile(this.addFactory.phone)){
         showNotice('error', '提示', '手机格式不对!')
      }else {
        this.handleAddfactory(this.addFactory)
      }
    },
    handleCloseDialog() {
      console.log("子组件关闭")
      this.$emit('handleCloseDialog');
    },
    handleCloseDialogUpdate() {
      this.$emit('handleRefresh');
      this.$emit('handleCloseDialog');
    },
    handleAddfactory(obj) {
      addFactory(obj).then((res) => {
        if (res.code == "000000") {
           showNotice('success', '提示', '保存成功!')
          this.$emit('handleRefresh');
          this.$emit('handleCloseDialog');
        }
      });
    }
  },
  watch: {
    editFactory: {
      deep: true,  // 深度监听
      handler(newVal, oldVal) {
        console.log(newVal, oldVal)
      }
    }
  }
}
</script>

<style rel='stylesheet/scss' lang='scss' scoped>
.produceFactoryDialog {
  width: 100%;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  min-height: 450px;
  background-color: #f5f5f5;
  border-radius: 5px;
  .con {
    padding-top: 16px;
  }
  .panelWrap {
    height: 100%;
    position: absolute;
    width: 100%;
  }
  .con-row {
    padding: 10px 0 0 0;
    .inputLable {
      .name {
        width: 36%;
        text-align: right;
      }
      .input {
        margin-left: 3px;
      }
    }
    .textarea {
      width: 260px !important;
      border-style: solid;
      border-width: 1px;
      border-color: var(--inputbc);
      outline: none;
      height: 70px;
      border-radius: 3px;
    }
  }
  .footerBtn {
    .defaultbtn {
      width: 75px;
      height: 32px;
    }
  }
}
</style>
